//
//  TalkInputView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/1.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

protocol TalkInputDelegate {
    func talkInput_confirmBtnAction(inputView:TalkInputView)
    func talkInput_otherBtnAction(inputView:TalkInputView,senber:ZHButton)
}

class TalkInputView: NSView {
    
    var delegate:TalkInputDelegate?
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        self.addSubview(barrageBg)
        barrageBg.snp.makeConstraints { (make) in
            make.bottom.centerX.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        barrageBg.addSubview(toLab)
        toLab.snp.makeConstraints { (make) in
            make.height.equalTo(18)
            make.top.equalTo(10)
            make.left.equalTo(10)
        }
        
        barrageBg.addSubview(otherBtn)
        otherBtn.snp.makeConstraints { (make) in
            make.width.equalTo(20)
            make.height.equalTo(20)
            make.top.equalTo(10)
            make.right.equalTo(-10)
        }
        
        
        barrageBg.addSubview(teView)
        teView.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-70)
            make.left.equalTo(10)
            make.top.equalTo(40)
            make.bottom.equalTo(-20)
        }
        
        barrageBg.addSubview(confirmBtn)
        confirmBtn.snp.makeConstraints { (make) in
            make.width.equalTo(40)
            make.right.equalTo(-10)
            make.top.equalTo(40)
            make.bottom.equalTo(-20)
        }
    }
    
    lazy var barrageBg: NSView = {
        let view = NSView.init(frame: NSRect.zero)
        view.wantsLayer = true
        view.layer?.cornerRadius = 1
        view.layer?.masksToBounds = true
        view.layer?.borderColor = color_gray(30).cgColor
        view.layer?.borderWidth = 1
        view.layer?.backgroundColor = color_dark60.cgColor
        return view
    }()
    
    lazy var toLab: NSLabel = {
        let lab = NSLabel.label(title: "发送:所有人", textColor: color_dark160, font: NSFont.systemFont(ofSize: 12))
        lab.sizeToFit()
        return lab
    }()
    
    lazy var otherBtn: ZHButton = {
        let btn = ZHButton.init()
        btn.zh_title = ".."
        btn.zh_font = NSFont.systemFont(ofSize: 18)
        btn.zh_color = color_dark160
        btn.zh_backgroundColor = NSColor.clear
        btn.hasBorder = true
        btn.zh_cornerRadius = 3
        btn.zh_borderColor = color_dark160
        btn.zh_borderWidth = 1
        btn.target = self
        btn.action = #selector(otherBtnAction(senber:))
        return btn
    }()
    
    
    lazy var teView: BaseTextView = {
        let view = BaseTextView.init(frame: NSRect.zero)
        view.txView.isEditable = true
        view.txView.delegate = self
        view.txView.backgroundColor = color_dark38
        view.txView.font = NSFont.systemFont(ofSize: 13)
        return view
    }()
    
    
    lazy var confirmBtn: ZHButton = {
        let btn = ZHButton()
        btn.zh_title = "确定".localized()
        btn.zh_font = NSFont.systemFont(ofSize: 13)
        btn.zh_color = NSColor.white
        btn.zh_backgroundColor = color_dark90
        btn.hasBorder = true
        btn.zh_cornerRadius = 3
        btn.action = #selector(confirmBtnAction)
        btn.target = self
        
        return btn
    }()
    
    
    @objc func confirmBtnAction() {
        if self.delegate != nil {
            self.delegate?.talkInput_confirmBtnAction(inputView: self)
        }
    }
    
    @objc func otherBtnAction(senber:ZHButton) {
        if self.delegate != nil {
            self.delegate?.talkInput_otherBtnAction(inputView: self,senber:senber)
        }
    }
}

extension TalkInputView:NSTextViewDelegate {
    
}
